//
//  NKBespokeViewController.m
//  NewKY
//
//  Created by Dee on 2016/11/12.
//  Copyright © 2016年 Dee. All rights reserved.
//

#import "NKBespokeViewController.h"
#import <Masonry.h>
#import "HLBespokeView.h"
#import "HLTableViewController.h"
#import "HLDoctorDetailsViewController.h"
#import "HLWayTableViewController.h"
#import "HLSyndromeTableViewController.h"
#import "HLDoctorListTableViewController.h"

@interface NKBespokeViewController ()

@property (nonatomic,strong) HLBespokeView *bespokeView;

@property (nonatomic,strong) HLTableViewController *sickCategoryTableVC;

@property (nonatomic,strong) HLSyndromeTableViewController *syndrometbVC;

@end

@implementation NKBespokeViewController{
    
    NSArray * _modelArr ;
}




- (void)viewDidLoad {
    [super viewDidLoad];

    [self setupUI];
    
    self.navigationItem.title = @"疾病详情选择";
    
//    [self postMethod];
    
    [self postSickMethod];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(passAction:) name:@"passValue" object:nil];
    
    
}

- (void)postMethod{
    
    //根据疾病得到医生数量接口
    NSString *url = @"http://iosapi.itcast.cn/doctor/matchedDoctorCount.json.php";
    NSDictionary *parameters = @{@"ci1_id":@1,@"ci2_id":@3,@"ci3_id":@3,@"diagnosis_type":@0,@"is_confirmed":@1,@"user_id":@1000089, @"has_diagnosis":@2};
    
    [NetWorkingManager sendPOSTDataWithPath:url withParamters:parameters withProgress:^(float progress) {
        
    } success:^(BOOL isSuccess, id responseObject) {
        if(isSuccess){
            
            NSDictionary * dict = responseObject[@"data"];
            
            self.bespokeView.doctorCount = [dict[@"doctor_count"]intValue];
            
        }
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];

}

- (void)postSickMethod{
    
    //选择疾病细分列表接口
    NSString *url = @"http://iosapi.itcast.cn/doctor/searchCI3List.json.php";
    NSDictionary *parameters = @{@"page":@1,@"page_size":@15,@"ci1_id":@(self.ci1_id),@"keyword":@""};
    
    [NetWorkingManager sendPOSTDataWithPath:url withParamters:parameters withProgress:^(float progress) {
        
    } success:^(BOOL isSuccess, id responseObject) {
        if(isSuccess){
            
            NSArray * dictArr = responseObject[@"data"];
            
            NSArray * modelArr = [NSArray modelArrayWithClass:[HLSickCategoryModel class] json:dictArr];
            
            _modelArr = modelArr;
            self.sickCategoryTableVC.ModelArr = modelArr;
        }
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
    }];
    
}

-(void)setupUI{
    
    self.bespokeView = [[HLBespokeView alloc]init];
    
    
    self.sickCategoryTableVC = [[HLTableViewController alloc]initWithStyle:UITableViewStylePlain];
    
    __weak typeof(self) weakSelf = self;
    

    self.sickCategoryTableVC.datablock = ^(NSString * str,NSInteger ci2_id){
        
        weakSelf.bespokeView.sickStr = str;
        weakSelf.syndrometbVC.ci1_id = weakSelf.ci1_id;
        weakSelf.syndrometbVC.ci2_id = ci2_id;
        
        weakSelf.bespokeView.sickSelect = ci2_id;
        
    };
    
    /*---通过block来Push进入控制器---*/
    self.bespokeView.sickCategoryBlock = ^(){
        
        [weakSelf.navigationController pushViewController:weakSelf.sickCategoryTableVC animated:YES];
    };
    
    self.syndrometbVC = [HLSyndromeTableViewController new];
    
    /*---并发症状的选择完的数据回调---*/
    self.syndrometbVC.dataArrBlock  = ^(NSArray * arr,BOOL select){
        
        //回调并发症选择的数据数组
        weakSelf.bespokeView.syndromeArr = arr;
        
        //并发症状是否选择
        weakSelf.synfromeSelect = select;
        
    };
    
    self.bespokeView.syndromeViewBlock = ^(){
        
        if (weakSelf.syndrometbVC.ci2_id == 0 ) {
            
            [SVProgressHUD setMinimumDismissTimeInterval:0.5];
            [SVProgressHUD showErrorWithStatus:@"请选择疾病类型"];
            
        }
        else{
            
            [weakSelf.navigationController pushViewController:weakSelf.syndrometbVC animated:YES];
        }
        
    };
    
    HLWayTableViewController * waytbVC = [HLWayTableViewController new];
    
    HLDoctorListTableViewController * doctorListTbVC = [HLDoctorListTableViewController new];
    
    waytbVC.datablock = ^(NSString *str){
        
        self.bespokeView.wayStr = str;
        
    };
    
    self.bespokeView.wayViewBlock = ^(){
        [weakSelf.navigationController pushViewController:waytbVC animated:YES];
    };
    
    self.bespokeView.BtnBlock = ^(){
        
        [weakSelf.navigationController pushViewController:doctorListTbVC animated:YES];
    };
    
    
    
    switch (self.ci1_id) {
        case 1:
            self.bespokeView.sickTypeStr = @"肿瘤";
            break;
        case 2:
            self.bespokeView.sickTypeStr = @"血液科";
            break;
        case 3:
            self.bespokeView.sickTypeStr = @"心血管";
            break;
        case 4:
            self.bespokeView.sickTypeStr = @"神经科";
            break;
        case 5:
            self.bespokeView.sickTypeStr = @"骨科";
            break;
        default:
            break;
    }
    
    [self.view addSubview:self.bespokeView];
    
    /*---布局---*/
    [self.bespokeView mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.equalTo(self.view.mas_topMargin);
        make.left.right.bottom.equalTo(self.view);
        
    }];
    
}


-(void)passAction:(NSNotification *)noti{
    
    NSNumber * NUM = noti.object;
    
    if (NUM.boolValue) {
        
        [self postMethod];
    }
    
    
}





@end
